﻿using System;
using System.Collections.Generic;
using System.Text;
using Osteox.ManagedCv;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;

namespace HelloWorld
{
    [StructLayout(LayoutKind.Explicit, Size=120)]
    struct a
    {
        [FieldOffset(0)]
        int abc;
    }
    class Program
    {
        static void Main(string[] args)
        {
            CvException.TurnRaiseException(true);
            try
            {
                string path = @"C:\Users\Public\Pictures\Sample Pictures";
                path = Path.Combine(path, "Penguins.jpg");
                using (ManagedImage image = ManagedCvInvoke.LoadImageW(path))
                {
                    ManagedArrPixelAccessorBgr8U accessor = new ManagedArrPixelAccessorBgr8U(image);
                    Bgr<byte> pixel = new Bgr<byte>();
                    pixel.R = 255;
                    pixel.G = 0;
                    pixel.B = 0;
                    Trace.WriteLine(DateTime.Now.Ticks);
                    for (int row = 100; row < image.Height - 100; row++)
                    {
                        for (int col = 100; col < image.Width - 100; col++)
                        {
                            accessor[row, col] = pixel;
                        }
                    }
                    Trace.WriteLine(DateTime.Now.Ticks);
                    ManagedCvInvoke.Smooth(image, image, SmoothType.Median, 7, 7);

                    Point2D32s start = new Point2D32s(10, 10);
                    Point2D32s end = new Point2D32s(300, 300);
                    Scalar color = new Scalar(255, 255, 255, 255);
                    ManagedCvInvoke.Line(image, start, end, color);

                    ManagedFont font = new ManagedFont();
                    ManagedCvInvoke.InitFont(ref font, FontFlag.HersheySimplex, 2, 2);
                    ManagedCvInvoke.PutText(image, "Hello world", new Point2D32s(), font, color);

                    ManagedCvInvoke.NamedWindow("Hello world");
                    ManagedCvInvoke.ShowImage("Hello world", image);
                    ManagedCvInvoke.WaitKey();
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
    }
}
